//
//  CycleTool+VerifyTools.m
//  CDSBZX
//
//  Created by dihuijun on 17/3/2.
//  Copyright © 2017年 Cycle. All rights reserved.
//

#import "CycleTool+VerifyTools.h"

@implementation CycleTool (VerifyTools)



#pragma mark-验证手机号码
+ (BOOL)cycle_validateMobile:(NSString *)mobile
{
    //手机号以13， 15，18开头，八个 \d 数字字符
    NSString *phoneRegex = @"^(1[0-9])\\d{9}$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", phoneRegex];
    return [phoneTest evaluateWithObject:mobile];
    
}
#pragma mark-验证数字
+ (BOOL)cycle_validateBirthday:(NSString *)birthday
{
    NSString *passWordRegex = @"^[0-9]{8,8}+$";
    NSPredicate *passWordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",passWordRegex];
    return [passWordPredicate evaluateWithObject:birthday];
}

#pragma mark-验证密码
+ (BOOL)cycle_validatePassword:(NSString *)passWord
{
    NSString *passWordRegex = @"^[a-zA-Z0-9]{6,20}+$";
    NSPredicate *passWordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",passWordRegex];
    return [passWordPredicate evaluateWithObject:passWord];
}


#pragma mark- 昵称
+ (BOOL)cycle_validateNickname:(NSString *)nickname
{
    NSString *nicknameRegex = @"^[\u4e00-\u9fa5]{4,8}$";
    NSPredicate *passWordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",nicknameRegex];
    return [passWordPredicate evaluateWithObject:nickname];
}
#pragma mark --- 验证用户名
+ (BOOL)cycle_validateUserName:(NSString *)name{
    NSString *userNameRegex = @"^[A-Za-z0-9]{6,20}+$";
    NSPredicate *userNamePredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",userNameRegex];
    BOOL B = [userNamePredicate evaluateWithObject:name];
    return B;
}

#pragma mark- 身份证号
+ (BOOL)cycle_validateIdentityCard:(NSString *)identityCard
{
    BOOL flag;
    if (identityCard.length <= 0) {
        flag = NO;
        return flag;
    }
    NSString *regex2 = @"^(\\d{14}|\\d{17})(\\d|[xX])$";
    NSPredicate *identityCardPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex2];
    return [identityCardPredicate evaluateWithObject:identityCard];
}
#pragma mark- 验证邮编
+ (BOOL)cycle_validatePostCode:(NSString *)postCode
{
    NSString *passWordRegex = @"^[0-9]{6,6}+$";
    NSPredicate *passWordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",passWordRegex];
    return [passWordPredicate evaluateWithObject:postCode];
}
#pragma mark- 验证验证码
+ (BOOL)cycle_validateCode:(NSString *)code
{
    NSString *passWordRegex = @"^[0-9]{4,4}+$";
    NSPredicate *passWordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",passWordRegex];
    return [passWordPredicate evaluateWithObject:code];
}

#pragma mark- 验证emile
+ (BOOL)cycle_validateEmile:(NSString *)emile
{
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    return [emailTest evaluateWithObject:emile];
}

#pragma mark- 验证生日和身份证号
+ (BOOL)cycle_validateBirthday:(NSString *)birthday andIdentityCard:(NSString *)identityCard
{
    if ([birthday length] < 10 || [identityCard length] < 18)
    {
        return NO;
    }
    NSString *tempStr1 = [birthday substringToIndex:4];
    NSRange range = NSMakeRange(5, 2);
    NSString *tempStr2 = [birthday substringWithRange:range];
    NSString *tempStr3 = [birthday substringFromIndex:8];
    NSMutableString *mStr = [NSMutableString string];
    [mStr appendFormat:@"%@%@%@",tempStr1, tempStr2, tempStr3];
    
    
    NSRange rangeCard = NSMakeRange(6, 8);
    NSString *birthdayCard = [identityCard substringWithRange:rangeCard];
    
    if ([mStr isEqualToString:birthdayCard])
    {
        return YES;
    }
    else
    {
        return NO;
    }
}



#pragma mark- IOS 开发中判断字符串是否为空字符的方法
+ (BOOL)cycle_validateIsBlankString:(NSString *)string
{
    if (string == nil || string == NULL) {
        return YES;
    }
    if ([string isKindOfClass:[NSNull class]]) {
        return YES;
    }
    if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0) {
        return YES;
    }
    return NO;
}


#pragma mark- 验证是否为中文
+ (BOOL)cycle_validateIsChinese:(NSString *)string
{
    NSString *match=@"(^[\u4e00-\u9fa5]+$)";
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF matches %@", match];
    
    return [predicate evaluateWithObject:self];
}
#pragma mark ---  车型
+ (BOOL)cycle_validateCarType:(NSString *)CarType
{
    NSString *CarTypeRegex = @"^[\u4E00-\u9FFF]+$";
    NSPredicate *carTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",CarTypeRegex];
    return [carTest evaluateWithObject:CarType];
}
#pragma mark -- 车牌号验证
+ (BOOL)cycle_validateCarNo:(NSString *)carNo
{
    NSString *carRegex = @"^[\u4e00-\u9fa5]{1}[a-zA-Z]{1}[a-zA-Z_0-9]{4}[a-zA-Z_0-9_\u4e00-\u9fa5]$";
    NSPredicate *carTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",carRegex];
    NSLog(@"carTest is %@",carTest);
    return [carTest evaluateWithObject:carNo];
}


@end
